package com.mojo.collection.queue;

import java.util.*;

/**
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/1/26 13:38
 */
public class QueueDemo {
    public static void main(String[] args) {
        //队列的常用方法
        Queue<Object> queue = new LinkedList<>();
        queue.add(2);
        queue.offer(1);
        System.out.println(queue.poll());
        System.out.println(queue.poll());
        System.out.println(queue.poll());
        //System.out.println(queue.element());
        //优先队列（可排序,元素需要）
        PriorityQueue<User> queue1 = new PriorityQueue<>(Comparator.comparing(o -> o.name));
        queue1.add(new User("mojo"));
        queue1.add(new User("mojo2"));
        queue1.add(new User("mojo1"));
        System.out.println(queue1.poll());
        System.out.println(queue1.poll());
        System.out.println(queue1.poll());

        //双向队列deque
        Deque<Object> deque = new LinkedList<>();
        deque.offerFirst(1);
        deque.offerLast(2);
        System.out.println(deque.getFirst());
        System.out.println(deque.getFirst());
    }


    private static class User {
        public String name;

        public User(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return new StringJoiner(", ", User.class.getSimpleName() + "[", "]")
                    .add("name='" + name + "'")
                    .toString();
        }
    }
}
